package com;


/**
 * Description: 此处设计类加载的懒汉模式
 *
 * @Autor: Rolin
 * datetime: 09-09-9:22
 */
public class ClassLoaderTest01 {
    public static void main(String[] args) {
        System.out.println(LazyInit.getInstance());
        System.out.println(LazyInit.getInstance());

    }

}

class LazyInit{

    public static void test(){
        System.out.println("test begin!");
    }

    //构造方法私有化，在初始化阶段访问init
    private LazyInit() {}

    //内部类
    private static class LazyHolder{
        //类加载初始化仅仅只有一次
       private static final LazyInit lazyInit = new LazyInit() ;
       static {
           System.out.println("lazy init!");
       }
    }

    //外部调用单例模式 对象的方法
    public static LazyInit getInstance(){
       return LazyHolder.lazyInit;
    }
}

